export class CfgGame01 implements ICfgData {
	public lv: number = 0
	public grid: number[]
	public pad: number[]
	public timer: number = 0
	public duration: number = 0
	public wallShowTime: number[]
	public wallWaitTime: number[]
	public loop = 1

	public parseData(jsonData: any): void {
		this.lv = jsonData.lv

		this.grid = Tool.splitCover(jsonData.grid, 1, parseInt)
		this.pad = Tool.splitCover(jsonData.pad, 1, parseInt)
		this.wallShowTime = Tool.splitCover(jsonData.wallShowTime, 1, parseFloat)
		this.wallWaitTime = Tool.splitCover(jsonData.wallWaitTime, 1, parseFloat)

		this.timer = jsonData.timer;
		this.duration = jsonData.duration
	}
}

export class CfgGame02 implements ICfgData  {
	public lv: number = 0
	public timer: number = 0
	public star_min: number = 0
	public star_max: number = 0
	public barrier_min: number = 0
	public barrier_max: number = 0
	public gap: number = 0
	public speed: number = 0
	public goal: number = 0
	public duration: number = 0

	public parseData(jsonData: any): void {
		this.lv = jsonData.lv
		this.timer = jsonData.timer
		this.star_min = jsonData.star_min
		this.star_max = jsonData.star_max
		this.barrier_min = jsonData.barrier_min
		this.barrier_max = jsonData.barrier_max
		this.gap = jsonData.gap
		this.speed = jsonData.speed
		this.goal = jsonData.goal
		this.duration = jsonData.duration
	}
}

export class CfgGame03 implements ICfgData {
	public lv: number = 0
	public loop: number = 0
	public startCountDown: number[] 
	public cd: number[]
	public count: number[]
	public duration: number = 0

	public parseData(jsonData: any): void {
		this.lv = jsonData.lv
		this.loop = 1
		this.duration = jsonData.duration
		
		this.cd = Tool.splitCover(jsonData.cd, this.loop, parseFloat)
		this.startCountDown = Tool.splitCover(jsonData.startCountDown, this.loop, parseFloat)
		this.count = Tool.splitCover(jsonData.count, this.loop, parseInt)
	}
}

export class CfgGame04 implements ICfgData {
	public lv: number = 0

	countDown = 1.5
    persons: number
	person_repeat: number
	name_repeat: string
    spell_repeat: string;
    question = 5;
    option = []

	public parseData(jsonData: any): void {
		this.lv = jsonData.lv
		this.countDown = jsonData.countDown
		this.persons = jsonData.persons
		this.person_repeat = jsonData.person_repeat
		this.name_repeat = jsonData.name_repeat === 0 ? "0" : jsonData.name_repeat
		this.spell_repeat = jsonData.spell_repeat === 0 ? "0" : jsonData.spell_repeat
		this.question = jsonData.question
		this.option = Tool.splitCover(jsonData.option, this.question, parseInt)
	}
}

export class CfgGame05 implements ICfgData {
	public lv: number = 0

	countdown = 2
    createRate = 1 / 3.0
	downSpeed = 300
	type="2_1_0.5,3_1_0.5"
    timeLimit = 60;
    maxMissCount = 1

	public parseData(jsonData: any): void {
		this.lv = jsonData.lv
		this.countdown = jsonData.countdown
		this.createRate = jsonData.createRate
		this.downSpeed = jsonData.downSpeed
		this.timeLimit = jsonData.timeLimit
		this.maxMissCount = jsonData.maxMissCount
		this.type = jsonData.type
	}
}

export class CfgGame06 implements ICfgData {
	public lv: number = 0

	countdown = 0.5
    tipsDealy = 0.2
    targetRate = 0.6
    speed = 0.25
    canMissRate = 0.3
    canErrorCount = 1
    timeLimit = 60

	public parseData(jsonData: any): void {
		this.lv = jsonData.lv
		this.countdown = jsonData.countdown
		this.tipsDealy = jsonData.tipsDealy
		this.targetRate = jsonData.targetRate
		this.speed = jsonData.speed
		this.canMissRate = jsonData.canMissRate
		this.canErrorCount = jsonData.canErrorCount
		this.timeLimit = jsonData.timeLimit
	}
}

export class CfgGame07 implements ICfgData {
	public lv: number = 0
	public timer: number = 0
	public count: number = 0
	public count_add: number = 0
	public keep1: number = 0
	public keep2: number = 0

	parseData(jsonData: any): void {
		this.lv = jsonData.lv
		this.timer = jsonData.timer
		this.count = jsonData.count
		this.count_add = jsonData.count_add
		this.keep1 = jsonData.keep1
		this.keep2 = jsonData.keep2
	}
}

export class CfgGame08 implements ICfgData {
	public lv: number = 0
	public duration: number = 0
	parseData(jsonData: any): void {
		this.lv = jsonData.lv
		this.duration = jsonData.duration
	}
}

export class CfgGame09 implements ICfgData {
	public lv: number = 0
	public timer: number = 0
	public keep: number = 0
	public fill_count: number = 0
	public colors: number = 0
	public error_count: number = 0
	public duration: number = 0

	parseData(jsonData: any): void {
		this.lv = jsonData.lv
		this.timer = jsonData.timer
		this.keep = jsonData.keep
		this.fill_count = jsonData.fill_count
		this.colors = jsonData.colors
		this.error_count = jsonData.error_count
		this.duration = jsonData.duration
	}
}

export class CfgGame10 implements ICfgData {
	public lv: number = 0
	public timer: number = 0
	public ovenCount: number = 0
	public foodCount: number[]
	public optionFoodCount: number = 0
	public timeLimit: number = 0
	public canErrorCount: number = 0
	public cookingTime: number = 0
	public fireTime: number = 0

	parseData(jsonData: any): void {
		this.lv = jsonData.level
		this.timer = jsonData.timer
		this.ovenCount = jsonData.ovenCount
		this.optionFoodCount = jsonData.optionFoodCount
		this.timeLimit = jsonData.timeLimit
		this.canErrorCount = jsonData.canErrorCount
		this.cookingTime = jsonData.cookingTime
		this.fireTime = jsonData.fireTime

		this.foodCount = Tool.splitCover(jsonData.foodCount, this.ovenCount, parseInt, ",")
	}
}

export class CfgGame12 implements ICfgData {
	public lv: number = 0
	public timer: number = 0
	public grid: number = 0
	public ship: number = 0
	public sub: number = 0
	public timeLimit: number = 0

	parseData(jsonData: any): void {
		this.lv = jsonData.level
		this.timer = jsonData.timer
		this.grid = jsonData.grid
		this.ship = jsonData.ship
		this.sub = jsonData.sub
		this.timeLimit = jsonData.timeLimit
	}
}

export class CfgGame14 implements ICfgData {
	public lv: number = 0
	public timer: number = 0
	public ticket: number = 0
	public superPosition: number = 0
	public qustionCount: number = 0
	public blankCount: number[]
	public anwerAll: number = 0
	public timeLimit: number = 0
	parseData(jsonData: any): void {

		this.lv = jsonData.level
		this.timer = jsonData.timer
		this.ticket = jsonData.ticket
		this.superPosition = jsonData.superPosition
		this.qustionCount = jsonData.qustionCount
		this.anwerAll = jsonData.duration
		this.timeLimit = jsonData.timeLimit

		this.blankCount = Tool.splitCover(jsonData.blankCount, this.ticket, parseInt, ",")
	}
}

export default interface ICfgData {
	parseData(jsonData: any): void;
}

class Tool {
	public static splitCover (str: any, count: number, call: any, sprtor="|") {
		let arr
		if (typeof str == "number") {
			str = str.toString()
		}
		
		if (str.indexOf(sprtor) == -1) {
			let n = call(str)
			arr = []
			for (let i=0;i< count; i++) {arr.push(n)}
		}else{
			arr = str.split(sprtor).map(e=>call(e))

			if (count > arr.length) {
				let last = arr[arr.length-1]
				for (let i=0;i<count-arr.length;i++) {
					arr.push(last)
				}
			}
		}

		return arr
	}	
}

/**
 * public void NOSomethingA()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingB()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingC()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingD()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingE()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingF()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingG()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingH()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingI()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingJ()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingK()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingL()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingM()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingN()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingO()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingP()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingQ()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingR()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingS()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingT()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingU()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingV()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
 */